﻿/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A
 * copy of the license can be found at http://go.microsoft.com/fwlink/?LinkID=131993. If
 * you cannot locate the Microsoft Public License, please send an email to
 * mixon@microsoft.com. By using this source code in any fashion, you are agreeing to
 * be bound by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 *
 * ***************************************************************************/

using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace MIXOnline.Descry
{

    /// <summary>
    /// This class houses one FriendFeed Entry item according to FriendFeed schema.
    /// An IsChecked property is added on the User and Service classes.
    /// </summary>
    /// <notes>
    /// Some of the classes implement INotifyPropertyChanged and and IEqualityComparer
    /// is used to determine item equality for LINQ comparisons
    /// </notes>
    public class Entry
    {
        private DateTime _Updated;
        public DateTime Updated
        {
            get { return _Updated; }
            set { _Updated = value; }
        }
        
        private string _Title;
        public string Title
        {
            get { return _Title; }
            set { _Title = value; }
        }

        private Uri _Link;
        public Uri Link
        {
            get { return _Link; }
            set { _Link = value; }
        }

        private bool _Anonymous;
        public bool Anonymous
        {
            get { return _Anonymous; }
            set { _Anonymous = value; }
        }

        private DateTime _Published;
        public DateTime Published
        {
            get { return _Published; }
            set { _Published = value; }
        }

        private bool _Hidden;
        public bool Hidden
        {
            get { return _Hidden; }
            set { _Hidden = value; }
        }

        private Guid _Id;
        public Guid Id
        {
            get { return _Id; }
            set { _Id = value; }
        }

        private User _User;
        public User User
        {
            get { return _User; }
            set { _User = value; }
        }

        private Service _Service;
        public Service Service
        {
            get { return _Service; }
            set { _Service = value; }
        }

        private List<Media> _Media;
        public List<Media> Media
        {
            get { return _Media; }
            set { _Media = value; }
        }

        private int _Likes;
        public int Likes
        {
            get { return _Likes; }
            set { _Likes = value; }
        }

        private int _Comments;
        public int Comments
        {
            get { return _Comments; }
            set { _Comments = value; }
        }

    }

    public class User : INotifyPropertyChanged
    {
        private Uri _ProfileUrl;

        public Uri ProfileUrl
        {
            get { return _ProfileUrl; }
            set { _ProfileUrl = value; }
        }
        private string _NickName;

        public string NickName
        {
            get { return _NickName; }
            set { _NickName = value; }
        }
        private Guid _Id;

        public Guid Id
        {
            get { return _Id; }
            set { _Id = value; }
        }
        private string _Name;

        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        private bool _isChecked;

        public bool IsChecked
        {
            get { return _isChecked; }
            set
            {
                _isChecked = value;
                NotifyPropertyChanged("IsChecked");
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        #endregion
    }

    public class Service : INotifyPropertyChanged
    {
        private Uri _ProfileUrl;

        public Uri ProfileUrl
        {
            get { return _ProfileUrl; }
            set { _ProfileUrl = value; }
        }
        private string _IconUrl;

        public string IconUrl
        {
            get { return _IconUrl; }
            set { _IconUrl = value; }
        }
        private string _Id;

        public string Id
        {
            get { return _Id; }
            set { _Id = value; }
        }
        private string _Name;

        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        private bool _isChecked;

        public bool IsChecked
        {
            get { return _isChecked; }
            set
            {
                _isChecked = value;
                NotifyPropertyChanged("IsChecked");
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        #endregion
    }

    public class Media
    {

        private string _Title;
        public string Title
        {
            get { return _Title; }
            set { _Title = value; }
        }

        private string _Player;
        public string Player
        {
            get { return _Player; }
            set { _Player = value; }
        }

        private Uri _Link;
        public Uri Link
        {
            get { return _Link; }
            set { _Link = value; }
        }

        private List<MediaItem> _Thumbnails;
        public List<MediaItem> Thumbnails
        {
            get { return _Thumbnails; }
            set { _Thumbnails = value; }
        }

        private List<MediaItem> _Content;
        public List<MediaItem> Content
        {
            get { return _Content; }
            set { _Content = value; }
        }

        private List<MediaItem> _Enclosures;
        public List<MediaItem> Enclosures
        {
            get { return _Enclosures; }
            set { _Enclosures = value; }
        }
    }
    public class MediaItem
    {
        private string _Url;
        public string Url
        {
            get { return _Url; }
            set { _Url = value; }
        }

        private string _Type;
        public string Type
        {
            get { return _Type; }
            set { _Type = value; }
        }

        private int _Width;
        public int Width
        {
            get { return _Width; }
            set { _Width = value; }
        }

        private int _Height;
        public int Height
        {
            get { return _Height; }
            set { _Height = value; }
        }

        public MediaItem()
        {
            this._Type = null;
        }
    }

    public class ServiceEqualityComparer : IEqualityComparer<Service>
    {
        public bool Equals(Service x, Service y)
        {
            return (x.Id == y.Id);
        }

        public int GetHashCode(Service obj)
        {
            return base.GetHashCode();
        }
    }

    public class UserEqualityComparer : IEqualityComparer<User>
    {
        public bool Equals(User x, User y)
        {
            return (x.Id == y.Id);
        }

        public int GetHashCode(User obj)
        {
            return base.GetHashCode();
        }
    }

    public class EntryEqualityComparer : IEqualityComparer<Entry>
    {
        public bool Equals(Entry x, Entry y)
        {
            return (x.Id == y.Id);
        }

        public int GetHashCode(Entry obj)
        {
            return base.GetHashCode();
        }
    }


    /*
<entry>
<updated>2008-08-15T20:45:06Z</updated>
<service>
<profileUrl>http://twitter.com/hanshu</profileUrl>
<iconUrl>http://friendfeed.com/static/images/icons/twitter.png?v=436161fcd23ab1587cfc5b96807ba5d2</iconUrl>
<id>twitter</id>
<name>Twitter</name>
</service>
<title>Driving GREEEEN now to save gas!</title>
<link>http://twitter.com/hanshu/statuses/888837852</link>
<anonymous>False</anonymous>
<published>2008-08-15T20:45:06Z</published>
<hidden>False</hidden>
<id>42ab75aa-786f-dc47-797c-b635720f5f98</id>
<user>
<profileUrl>http://friendfeed.com/hanshu</profileUrl>
<nickname>hanshu</nickname>
<id>9dd6795c-8042-11dd-acaf-003048343a40</id>
<name>Hans</name>
</user>
</entry>
*/
    /*
      <entry>
        <updated>2008-09-18T00:34:11Z</updated>
        <service>
          <profileUrl>http://www.amazon.com/</profileUrl>
          <iconUrl>http://friendfeed.com/static/images/icons/amazon.png?v=878f56bf21f50558440b9692e6e843cd</iconUrl>
          <id>amazon</id>
          <name>Amazon.com</name>
        </service>
        <title>HP Pavilion DV9910US 17-inch Laptop (2.00 GHz AMD Turion X2 Dual Core Mobile TL-60 Processor, 3 GB RAM, 250 GB Hard Drive, DVD Drive, Vista Premium)</title>
        <media>
          <enclosures></enclosures>
          <title></title>
          <content></content>
          <player></player>
          <link>http://www.amazon.com/dp/B0019HGRH8/</link>
          <thumbnail>
            <url>http://ecx.images-amazon.com/images/I/51OWjOBx4oL._SL75_.jpg</url>
            <width>75</width>
            <height>75</height>
          </thumbnail>
          <thumbnail>
            <url>http://ecx.images-amazon.com/images/I/51OWjOBx4oL._SL160_.jpg</url>
            <width>160</width>
            <height>160</height>
          </thumbnail>
          <thumbnail>
            <url>http://ecx.images-amazon.com/images/I/51OWjOBx4oL._SL500_.jpg</url>
            <width>500</width>
            <height>500</height>
          </thumbnail>
        </media>
        <link>http://www.amazon.com/dp/B0019HGRH8/</link>
        <anonymous>False</anonymous>
        <published>2008-09-18T00:34:11Z</published>
        <hidden>False</hidden>
        <id>e6fa6b5f-b1ff-f7c0-073c-003e9226f418</id>
        <user>
          <profileUrl>http://friendfeed.com/hanshu</profileUrl>
          <nickname>hanshu</nickname>
          <id>9dd6795c-8042-11dd-acaf-003048343a40</id>
          <name>Hans</name>
        </user>
      </entry>
    */
}
